﻿using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using MSP.Data.Domain;

namespace MSP.Data.Maps
{
    public class ProductMap : ClassMapping<Product>
    {
        public ProductMap()
        {
            Table("[PRODUCT]");
            Schema("dbo");
            Lazy(true);
            Id(x => x.Id,
               map =>
               {
                   map.Generator(Generators.HighLow,
                                 g =>
                                 g.Params(
                                     new { table = "T_NEXT_ID", column = "NEXT_ID", max_lo = "0", where = "type = 'PRODUCT'" }));
                   map.Column("ID");
               });
            Property(x => x.Barcode, map => map.Column("BARCODE"));
            Property(x => x.Name, map => map.Column("NAME"));
            Property(x => x.PurchasePrice, map => map.Column("PURCHASE_PRICE"));
            Property(x => x.SalePrice, map => map.Column("SALE_PRICE"));
            Property(x => x.Stock, map => map.Column("STOCK"));
            Property(x => x.Unit, map => map.Column("UNIT_ID"));
            Property(x => x.KdvPercent, map => map.Column("KDV_PERCENT"));
            Property(x => x.InKdv, map => map.Column("INKDV"));
            Property(x => x.DateCreated, map => map.Column("DATE_CREATED"));
            Property(x => x.DateEdited, map => map.Column("DATE_EDITED"));

            ManyToOne(x => x.ProductCategory, map =>
            {
                map.Column("PRODUCT_CATEGORY_ID");
                map.Cascade(Cascade.None);
            });

            ManyToOne(x => x.CreatedUser, map =>
            {
                map.Column("CREATED_USER");
                map.Cascade(Cascade.None);
            });

            ManyToOne(x => x.EditedUser, map =>
            {
                map.Column("EDITED_USER");
                map.Cascade(Cascade.None);
            });

        }
    }
}
